package club.xinghe.servlet.student;

import club.xinghe.biz.ExamBiz;
import club.xinghe.entity.Exam;
import club.xinghe.entity.Tk;
import club.xinghe.util.JsonServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/student/StuExamPageServlet")
public class StuExamPageServlet extends HttpServlet {
    @Override
    /**
     *
     * 异步分页调用，向studentExamPage.jsp页面传递信息
     *
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int eid= Integer.parseInt(request.getParameter("eid"));//获取试卷的id，eid
        ExamBiz examBiz=new ExamBiz();
        int countPage=examBiz.stuExamPageCountRowBiz(eid);//获取试卷的总题数,作为分页总页数
        int currNum= Integer.parseInt(request.getParameter("currPage"));//要显示的当前页码
        Tk onetk=examBiz.stuExamCurrentPageBiz(eid,currNum);//该页的试题信息
        ArrayList<Tk> tkArrayList=new ArrayList<>();
        tkArrayList.add(onetk);

        Map<String,Object> maps=new HashMap<>();
        maps.put("countPage",countPage);
        maps.put("currNum",currNum);
        maps.put("tkArrayList",tkArrayList);
        //将maps转化为JSon响应给前端
        JsonServlet.getJson(request,response,maps);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
